package com.eralink.unionuhfreader.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.eralink.unionuhfreader.MainActivity;
import com.eralink.unionuhfreader.MyApplication;
import com.eralink.unionuhfreader.R;
import com.eralink.unionuhfreader.base.BaseActivity;
import com.eralink.unionuhfreader.bean.AppMemberUserInfoRespVO;
import com.eralink.unionuhfreader.dialog.CommonDialog;
import com.eralink.unionuhfreader.http.Api;
import com.eralink.unionuhfreader.http.JsonCallBack;
import com.eralink.unionuhfreader.http.Result;
import com.lzy.okgo.model.Response;

public class MemberActivity extends BaseActivity {
    LinearLayout lynotmember,lyvip;
    CommonDialog cashRefundDialog;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member);
        lynotmember=findViewById(R.id.lynotmember);
        lyvip=findViewById(R.id.ly_vip);;
        lynotmember.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MemberActivity.this, ReadActivity.class));
                finish();
            }
        });
        lyvip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               showrefundDialog();
            }
        });
    }
    private void showrefundDialog() {
        cashRefundDialog = new CommonDialog(this, "请输入会员号或者扫描会员码").setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_cancel:

                        break;
                    case R.id.tv_confirm:
                        if (v.getTag()==null){
                            showToast("请输入你的会员手机号");
                        }else{
                            getmember(v.getTag().toString());
                        }
                        break;
                }

                //SystemUIUtils.setStickFullScreen(MainActivity.this.getWindow().getDecorView());
                cashRefundDialog.dismiss();
            }
        });
        cashRefundDialog.show();
    }

    private void getmember(String mobile) {
        Api.getmemberinfo(mobile,new JsonCallBack<Result<AppMemberUserInfoRespVO>>(){
            @Override
            public void onSuccess(Response<Result<AppMemberUserInfoRespVO>> response) {
               Result<AppMemberUserInfoRespVO> appMemberUserInfoRespVOResult=response.body();
               if (appMemberUserInfoRespVOResult.isSucess()){
                   MyApplication.memberUserInfoRespVO=appMemberUserInfoRespVOResult.getData();
                   startActivity(new Intent(MemberActivity.this, ReadActivity.class));
                   finish();
               }else {
                   showToast(appMemberUserInfoRespVOResult.getMsg());
               }
            }
        });
    }
}
